//
//  AppCenter.m
//  i5db
//
//  Created by iMuse on 15-5-12.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "AppCenter.h"
#define DefaultCellBackgroundColor @"44,167,234,0.75"
#define DefaultFont                @"Heiti SC"
#define DefaultFontItalic          @"Heiti SC"
#define DefaultFontBold            @"STHeitiSC-Medium"

@implementation AppCenter

static AppCenter * _singleton;

+(AppCenter*) singleton
{
    if (_singleton == nil)
    {
        _singleton = [[self alloc] init];
    }
    
    return  _singleton;
}
+(id) init
{
    if (self)
    {
        
    }
    
    return self;
}



+(NSString*) TengXuanWebService
{
    NSString * str = @"http://apis.map.qq.com/ws/place/v1/search";
    
    return str;
}

+(NSString*) string:(NSString*) str
{
    NSString *text = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];
    
    return text;
}

+ (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font maxHeight:(float) height maxWeight :(float)weight
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(weight, height)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    
    return rect.size;
}
+(NSMutableArray*)checkMaps
{
    NSArray *mapSchemeArr = @[@"comgooglemaps://",@"iosamap://navi",@"baidumap://map/"];
    
    NSMutableArray *appListArr = [[NSMutableArray alloc] initWithObjects:@"苹果地图", nil];
    
    for (int i = 0; i < [mapSchemeArr count]; i++) {
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[mapSchemeArr objectAtIndex:i]]]]) {
            if (i == 0) {
                [appListArr addObject:@"google地图"];
            }else if (i == 1){
                [appListArr addObject:@"高德地图"];
            }else if (i == 2){
                [appListArr addObject:@"百度地图"];
            }
        }
    }
    
   // [appListArr addObject:@"显示路线"];
    
    return appListArr;
}

+ (UIFont*) font:(NSString*)font
{
    NSArray* array = [font componentsSeparatedByString:@","];
    
    NSString* fontName = [array objectAtIndex:0];
    NSInteger fontSize = [(NSString*)[array objectAtIndex:1] integerValue];
    
    if([fontName isEqualToString:@"system"])
    {
        return [UIFont systemFontOfSize:fontSize];
    }
    else if([fontName isEqualToString:@"boldsystem"])
    {
        return [UIFont boldSystemFontOfSize:fontSize];
    }
    else if([fontName isEqualToString:@"italicsystem"])
    {
        return [UIFont italicSystemFontOfSize:fontSize];
    }
    else if([fontName isEqualToString:@"default"])
    {
        return [UIFont fontWithName:DefaultFont size:fontSize];
    }
    else if([fontName isEqualToString:@"italic"])
    {
        return [UIFont fontWithName:DefaultFontItalic size:fontSize];
    }
    else if([fontName isEqualToString:@"bold"])
    {
        return [UIFont fontWithName:DefaultFontBold size:fontSize];
    }
    else
    {
        return [UIFont fontWithName:fontName size:fontSize];
    }
}

+ (UIColor*) color:(NSString*)colorString
{
    if([colorString isEqualToString:@"clear"])
    {
        return [UIColor clearColor];
    }
    
    NSArray* colors = [colorString componentsSeparatedByString:@","];
    
    if([colors count]!=3 && [colors count]!=4)
    {
        colors = [DefaultCellBackgroundColor componentsSeparatedByString:@","];
    }
    
    float red   = [(NSString*)[colors objectAtIndex:0] floatValue];
    float green = [(NSString*)[colors objectAtIndex:1] floatValue];
    float blue  = [(NSString*)[colors objectAtIndex:2] floatValue];
    float alpha = 1;
    
    if([colors count]==4)
    {
        alpha = [(NSString*)[colors objectAtIndex:3] floatValue];
    }
    
    return [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha];
}
@end
